package com.insurance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.insurance.domain.ResponseResult;
import com.insurance.domain.entity.Case;
import com.insurance.domain.entity.Customer;
import com.insurance.domain.enums.AppHttpCodeEnum;
import com.insurance.domain.vo.CasePageVo;
import com.insurance.domain.vo.PageVo;
import com.insurance.mapper.CaseMapper;
import com.insurance.service.CaseService;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Case)表服务实现类
 *
 * @author makejava
 * @since 2023-04-22 09:50:46
 */
@Service("caseService")
public class CaseServiceImpl extends ServiceImpl<CaseMapper, Case> implements CaseService {

    @Override
    public ResponseResult listByPage(CasePageVo casePageVo) {
        LambdaQueryWrapper<Case> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.like(!ObjectUtils.isEmpty(casePageVo.getDiseases()),Case::getDiseases,casePageVo.getDiseases());
        queryWrapper.like(!ObjectUtils.isEmpty(casePageVo.getDoctor()),Case::getDoctor,casePageVo.getDoctor());
        queryWrapper.like(!ObjectUtils.isEmpty(casePageVo.getPrescription()),Case::getPrescription,casePageVo.getPrescription());
        queryWrapper.like(!ObjectUtils.isEmpty(casePageVo.getSurecord()), Case::getSurecord,casePageVo.getSurecord());
        queryWrapper.like(!ObjectUtils.isEmpty(casePageVo.getAdvice()), Case::getAdvice,casePageVo.getAdvice());
        Page<Case> page = new Page<>(casePageVo.getPageNo(), casePageVo.getPageSize());
        page(page,queryWrapper);
        List<Case> cases = page.getRecords();
        PageVo pageVo = new PageVo(cases, page.getTotal());
        return ResponseResult.okResult(pageVo);
    }

    @Override
    public ResponseResult addCase(Case case1) {
        if(save(case1)){
            return ResponseResult.okResult();
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.ADD_FAILED);
    }

    @Override
    public ResponseResult updateCase(Case case1) {
        if(updateById(case1)){
            return ResponseResult.okResult();
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.UPDATE_ERROR);
    }
}
